<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "sc_attr".
 *
 * @property integer $at_id
 * @property string $at_name
 *
 * @property Goodsattr[] $goodsattrs
 * @property ScAttrValue[] $scAttrValues
 */
class Scattr extends \yii\db\ActiveRecord
{
	private static $_items=array();
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'sc_attr';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['at_name'], 'required'],
            [['at_id'], 'integer'],
            [['at_name'], 'string', 'max' => 50]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'at_id' => '属性ID',
            'at_name' => '属性名',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getGoodsattrs()
    {
        return $this->hasMany(Goodsattr::className(), ['at_id' => 'at_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getScAttrValues()
    {
        return $this->hasMany(ScAttrValue::className(), ['at_id' => 'at_id']);
    }
    
    
    public static function items()
    {
    	//if(!isset(self::$_items))
    		self::loadItems();
    	return self::$_items;
    }
    
   public static function item()
    {
    	if(!isset(self::$_items))
    		self::loadItems();
    	return isset(self::$_items) ? self::$_items : false;
    }
    
    private static function loadItems()
    {
    	
    	self::$_items=array();
    	$models=self::find()->all();
    	foreach($models as $model)
    		self::$_items[$model->at_id]=$model->at_name;
    	
    	
    }
}
